package com.lsp.microcommon.exception;

import com.lsp.microcommon.common.CommonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {


    @ExceptionHandler(CommonException.class)
    public CommonResult commonException(CommonException e){

        if (e.getCode() != 0) {
            return CommonResult.error(e.getCode(), e.getMsg());
        } else {
            e.printStackTrace();
            return CommonResult.error(e.getMsg());
        }
    }


    @ExceptionHandler(Exception.class)
    public CommonResult exceptionHandler(Exception e){
        e.printStackTrace();
        return CommonResult.error("未知异常，请联系客服");
    }
}
